# -*- coding: utf-8 -*-

############################################################################
#
#   Copyright (c) 2020  Bresee, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#############################################################################

"""
Create Initial Resource
"""

import os
import sys
import socket
import utils.common.func as func
import utils.common.func as commfunc
import utils.common.log as log
import utils.config.appsvrini as appsvrini
import json

# Directory Resources

YUN_WORKMODE = True
COS_TYPE = True
hostname = socket.gethostname()
localUrl = "http://" + socket.gethostbyname(hostname) + ":33033/file/"  # 文件
localVideoUrl = "http://" + socket.gethostbyname(hostname) + ":33033/vlogvideo"  # 视频
localElement = "http://" + socket.gethostbyname(hostname) + ":33033/elements/" # 要素
system_ip = commfunc.get_host_ip()  #ip
element_path = ""
commom_path = func.getexepath() + "/cfg/vlog_common.ini"   # 数据库链接文件
# server = json.loads(appsvrini.get_server(commom_path)["inner_ip_groups"])





if 'win' in sys.platform:
    appdata = os.getenv('appdata')   # 获取环境变量键的值（存在），否则返回默认值
    rootpath = appdata + '/vlog'   # 根目录
    workpath = rootpath + '/work'  # 工作目录
else:
    rootpath = '/var/vlog'
    workpath = rootpath + '/work'


os.makedirs(rootpath, exist_ok=True)  # 当文件夹已经存在就不创建



LOGSPATH = rootpath + '/logs/'


RESPATH = rootpath + '/resource/'


UPLOADPATH = rootpath + '/upload/'


MATERIALPATH = rootpath + '/material/'


ELEMENTPATH = rootpath + '/element'


os.makedirs(rootpath, exist_ok=True)


os.makedirs(LOGSPATH, exist_ok=True)


os.makedirs(RESPATH, exist_ok=True)


os.makedirs(UPLOADPATH, exist_ok=True)


os.makedirs(ELEMENTPATH,exist_ok=True)

def mkpath(path):
    '''当文件夹已经存在就不创建'''
   
    os.makedirs(path, exist_ok=True)

def iniPath():
    iniPath = ""
    global element_path
    # 获取程序路径
    iniPath = func.getexepath() + "/cfg/vlog_Config.ini"
    element_path = "https://front-vlog-1311402863.cos.ap-nanjing.myqcloud.com/var/vlog/element/"

    return iniPath
